package com.opensistemas.spm.model;

import org.appfuse.model.BaseObject;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import java.io.Serializable;

@Entity
@Table(name="project")
@Inheritance(strategy= InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="project_type",  discriminatorType = DiscriminatorType.STRING)
abstract public class Project extends BaseObject implements Serializable {
    private Long id;
    private String name;
    private String description;
    private String projectType;
    private Set<Workflow> workflows = new HashSet<Workflow>(0);
    private Set<ProjectDate> projectDates = new HashSet<ProjectDate>(0);

    @Id  @GeneratedValue(strategy = GenerationType.AUTO)    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @Column(name="name", nullable=false, length=100)
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    @Column(name="description", nullable=false)
    public String getDescription() {
        return this.description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    @Column(name="project_type", nullable=false, length=50,insertable = false, updatable =false)
    public String getProjectType() {
        return this.projectType;
    }
    
    public void setProjectType(String projectType) {
        this.projectType = projectType;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="project")
    public Set<Workflow> getWorkflows() {
        return this.workflows;
    }
    
    public void setWorkflows(Set<Workflow> workflows) {
        this.workflows = workflows;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="project")
    public Set<ProjectDate> getProjectDates() {
        return this.projectDates;
    }
    
    public void setProjectDates(Set<ProjectDate> projectDates) {
        this.projectDates = projectDates;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Project pojo = (Project) o;

        if (name != null ? !name.equals(pojo.name) : pojo.name != null) return false;
        if (description != null ? !description.equals(pojo.description) : pojo.description != null) return false;
        if (projectType != null ? !projectType.equals(pojo.projectType) : pojo.projectType != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (name != null ? name.hashCode() : 0);
        result = 31 * result + (description != null ? description.hashCode() : 0);
        result = 31 * result + (projectType != null ? projectType.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("name").append("='").append(getName()).append("', ");
        sb.append("description").append("='").append(getDescription()).append("', ");
        sb.append("projectType").append("='").append(getProjectType()).append("', ");
        
        
        sb.append("]");
      
        return sb.toString();
    }

}
